package cuit.cx.activity;

import cuit.cx.util.StaticConstant;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class NavigationAct extends TabActivity {
	
	private RadioGroup radioGroup;
	private TabHost theHost;
	private RadioButton user_rb;
	private static final String TABHOST_JINRI = "jinri";
	private static final String TABHOST_BEGONE = "wangri";
	private static final String TABHOST_USER = "user";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.navigation);
        findView();
        initView();
    }
    
    void findView(){
    	
    	theHost = getTabHost();
    	radioGroup = (RadioGroup) findViewById(R.id.navigation_rg);
    	user_rb = (RadioButton) findViewById(R.id.navigation_user_rb);
    	
    }
    
    void initView(){
    	
    	if(StaticConstant.LoginUser == null){
    		
    		radioGroup.check(R.id.navigation_today_rb);
    		theHost.addTab(theHost.newTabSpec(TABHOST_JINRI).setIndicator(TABHOST_JINRI).setContent(new Intent(this, GroupTodayAct.class)));
        	theHost.addTab(theHost.newTabSpec(TABHOST_BEGONE).setIndicator(TABHOST_BEGONE).setContent(new Intent(this, GroupBegoneAct.class)));
        	theHost.addTab(theHost.newTabSpec(TABHOST_USER).setIndicator(TABHOST_USER).setContent(new Intent(this, LoginOrRegisterAct.class)));
        	
    	}else{
    		
    		radioGroup.check(R.id.navigation_user_rb);
    		user_rb.setText(StaticConstant.LoginUser.getName());
    		theHost.addTab(theHost.newTabSpec(TABHOST_USER).setIndicator(TABHOST_USER).setContent(new Intent(this, UserInfoAct.class)));
    		theHost.addTab(theHost.newTabSpec(TABHOST_JINRI).setIndicator(TABHOST_JINRI).setContent(new Intent(this, GroupTodayAct.class)));
    		theHost.addTab(theHost.newTabSpec(TABHOST_BEGONE).setIndicator(TABHOST_BEGONE).setContent(new Intent(this, GroupBegoneAct.class)));
    		
    	}
    	
    	
    	
    	
    	radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup arg0, int checkId) {
				
				switch (checkId) {
				case R.id.navigation_today_rb:
					
					theHost.setCurrentTabByTag(TABHOST_JINRI);
					
					break;
				case R.id.navigation_begone_rb:
					
					theHost.setCurrentTabByTag(TABHOST_BEGONE);
					
					break;
				case R.id.navigation_user_rb:
					
					theHost.setCurrentTabByTag(TABHOST_USER);
						
					break;

				default:
					
					break;
				}
				
			}
		});
    	
    }
    
    
    
}